package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import flc.ast.bean.RecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class PlayLocalAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public PlayLocalAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(82));
        addItemProvider(new PlayLocalProvider());
    }

    private class PlayLocalProvider extends BaseItemProvider<SelectMediaEntity> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_play_local;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivPlayLocalItemImg));
            baseViewHolder.setText(R.id.tvPlayLocalItemName, FileUtils.getFileName(bean.getPath()));
            baseViewHolder.setText(R.id.tvPlayLocalItemDuration, TimeUtil.getMmss(MediaUtil.getDuration(bean.getPath())));
            baseViewHolder.setText(R.id.tvPlayLocalItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getPath()), "yyyy/MM/dd"));
            baseViewHolder.setText(R.id.tvPlayLocalItemSize, ConvertUtils.byte2FitMemorySize(bean.getSize(), 3));
        }

    }

}
